Skip to content

Conversation

@sjakobi
Copy link
Member

@sjakobi sjakobi commented Oct 25, 2025

Context: #364


TODO:

  • How does the delete refactoring affect its performance?
  • delete'' -> deleteSubTree
  • What happens when the internal delete''.go function is removed and we recurse to delete'' itself?

@sjakobi
Copy link
Member Author

sjakobi commented Oct 25, 2025

Wow, the -fdebug assertions are paying off, I guess!

         valid:                             FAIL
          *** Failed! (after 54 tests and 15 shrinks):
          Exception:
            Data.HashMap.Internal.Array.shrink: Check failed:  _n >  (0 :: Int) (0 vs. 0)
            CallStack (from HasCallStack):
              error, called at ./Data/HashMap/Internal/Array.hs:225:39 in unordered-containers-0.2.20.1-inplace:Data.HashMap.Internal.Array
          fromList [(K {hash = -1, _x = B},0),(K {hash = -1, _x = A},0)]
          fromList [(K {hash = -1, _x = A},0),(K {hash = -1, _x = B},0)]
          Exception thrown while showing test case:
            Data.HashMap.Internal.Array.shrink: Check failed:  _n >  (0 :: Int) (0 vs. 0)
            CallStack (from HasCallStack):
              error, called at ./Data/HashMap/Internal/Array.hs:225:39 in unordered-containers-0.2.20.1-inplace:Data.HashMap.Internal.Array
          
          Use --quickcheck-replay="(SMGen 2214100628715094315 10962607274683585473,53)" to reproduce.
          Use -p '/Data.HashMap.Strict.difference.valid/' to rerun this test only.

@sjakobi
Copy link
Member Author

sjakobi commented Oct 25, 2025

So the failing assertion is this one, introduced in b73381e:

-- | The returned array is the same as the array given, as it is shrunk in place.
shrink :: MArray s a -> Int -> ST s (MArray s a)
shrink mary _n@(I# n#) =
CHECK_GT("shrink", _n, (0 :: Int))
CHECK_LE("shrink", _n, (unsafeLengthM mary))
ST $ \s -> case Exts.shrinkSmallMutableArray# (unMArray mary) n# s of
s' -> (# s', mary #)
{-# INLINE shrink #-}

I don't see an obvious technical reason why an array shouldn't be shrunk to length 0, apart from the fact that an array of length 0 is useless for storing elements. In the case of the new filter function, an array of length 0 seems like a perfectly valid result.

So I'll just change CHECK_GT to CHECK_GE.

At least in the context of `Array.filter` this seems useful and
valid.
@treeowl
Copy link
Collaborator

treeowl commented Oct 25, 2025

I agree that assertion is bogus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants